from config import config
import time
import jwt
#博客jwt
class Jwt():
    def __init__(self,id,name):
        self.key = config["key"]
        self.date = time.time()
        self.name = name
        self.id = id
        self.exp = self.date+(60*int(config["authDate"]))

    def genJwt(self):
        jsonobj = {
            "id":self.id,
            "name":self.name,
            "date":self.date,
            "exp":self.exp
        }
        return jwt.encode(jsonobj,self.key)

    @staticmethod
    def checkJwt(jwtstr):
        try:
            return jwt.decode(jwtstr,config["key"])
        except Exception:
            return None